var grid;
$(document).ready(function() {
    /////////////jehc扩展属性目的可方便使用（boot.js文件datatablesCallBack方法使用） 如弹窗分页查找根据条件 可能此时的form发生变化 此时 可以解决该类问题
    var opt = {
        searchformId:'searchForm'
    };
    var options = DataTablesPaging.pagingOptions({
        ajax:function (data, callback, settings){datatablesCallBack(data, callback, settings,'../xtGenerator/list',opt);},//渲染数据
        //在第一位置追加序列号
        fnRowCallback:function(nRow, aData, iDisplayIndex){
            jQuery('td:eq(1)', nRow).html(iDisplayIndex +1);
            return nRow;
        },
        order:[],//取消默认排序查询,否则复选框一列会出现小箭头
        //列表表头字段
        colums:[
            {
                sClass:"text-center",
                width:"50px",
                data:"xt_generator_id",
                render:function (data, type, full, meta) {
                    return '<label class="mt-checkbox mt-checkbox-single mt-checkbox-outline"><input type="checkbox" name="checkId" class="checkchild " value="' + data + '" /><span></span></label>';
                },
                bSortable:false
            },
            {
                data:"xt_generator_id",
                width:"50px"
            },
            {
                data:'xt_generator_tbname'
            },
            {
                data:'xt_generator_tbcomment'
            },
            {
                data:'xt_generator_state',
                render:function(data, type, row, meta) {
                    if(data == 1){
                        return "成功";
                    }
                    if(data == 2){
                        return "失败";
                    }
                }
            },
            {
                data:'is_one_to_many',
                render:function(data, type, row, meta) {
                    if(data == 1){
                        return '<font color=red>一对多表生成</font>';
                    }else if(data == 0){
                        return '单表生成';
                    }else{
                        return '<font color=green>缺省</font>';
                    }
                }
            },
            {
                data:'xt_generator_time'
            }
        ]
    });
    grid=$('#datatables').dataTable(options);
    //实现全选反选
    docheckboxall('checkall','checkchild');
    //实现单击行选中
    clickrowselected('datatables');
});

//新增
function addXtGenerator(generatorFlag,type){
    $('#defaultForm').bootstrapValidator({
        message:'此值不是有效的'
    });
    $('#defaultFrontForm').bootstrapValidator({
        message:'此值不是有效的'
    });
    $('#defaultGridForm').bootstrapValidator({
        message:'此值不是有效的'
    });
    $('#defaultSearchForm').bootstrapValidator({
        message:'此值不是有效的'
    });
    $('#defaultOneTwoManyForm').bootstrapValidator({
        message:'此值不是有效的'
    });
    $('#defaultOneTwoManyPageConfigForm').bootstrapValidator({
        message:'此值不是有效的'
    });
    var oneModalCount = 0 ;
    $('#oneBody').height(reGetBodyHeight()*0.75);
    $('#oneModal').modal({backdrop: 'static', keyboard: false});
    $('#oneModal').on("shown.bs.modal",function(){
        if(++oneModalCount == 1){
            $('#defaultForm')[0].reset();
            $('#defaultFrontForm')[0].reset();
            $('#defaultGridForm')[0].reset();
            $('#defaultSearchForm')[0].reset();
            $('#defaultPageConfigForm')[0].reset();
            $('#defaultOneTwoManyForm')[0].reset();
            getDisks("xt_generator_path");//加载路径
            getDbInfoList("xt_dbinfo_id");//加载数据源
            getXtUrlConfigList("rest_url_prefix");//加载地址配置
            // getColumnList();//加载字段列
            // createSearchHeader();//查询条件"清空并创建Header"
            // getPageConfigColumnList();//新增 编辑 详情等页面
            if(generatorFlag == 1){
                $("#is_one_to_many").val(1);
            }
            $("#kf_mode").val(1);
            if(type == 3){ //单表
                // $('a[href="#tab5"]').on('show.bs.tab', function(e) {
                //     e.preventDefault();
                // });
                console.log("禁用Tab");
                $('#newOneTwoMany').attr("disabled","disabled");
            }
            if(type == 4){//一对多
                console.log("解禁Tab");
                $('#newOneTwoMany').removeAttr("disabled");
            }
        }
        clearAll();
    });
    $('#defaultPageConfigForm').bootstrapValidator({
        message:'此值不是有效的'
    });
}

/**
 * 清空所有
 */
function clearAll(){
    createSearchHeader();
    createGridColumnHeader();
    createPageConfigColumnHeader();
    createOneTwoManyHeader();
}
//删除
function delXtGenerator(){
    if(returncheckedLength('checkchild') <= 0){
        toastrBoot(4,"请选择要删除的数据");
        return;
    }
    msgTishCallFnBoot("确定要删除所选择的数据？",function(){
        var id = returncheckIds('checkId').join(",");
        var params = {xt_generator_id:id,_method:'DELETE'};
        ajaxBReq('../xtGenerator/delete',params,['datatables'], null,'DELETE');
    })
}

function toXtGeneratorDetail(id){

}

//加载地址配置
function getXtUrlConfigList(id){
    ajaxBRequestCallFn("../xtUrlConfig/listAll",{},function(result){
        $("#"+id).empty();
        result = result.data;
        var str = "<option value=''>请选择</option>";
        $.each(result, function(i, item){
            var xt_url_location = item.xt_url_location;
            var xt_url_title = item.xt_url_title;
            str += "<option value=" + xt_url_location + ">" + xt_url_title + "</option>";
        })
        $("#"+id).append(str);
    });
}

//加载数据源
function getDbInfoList(id){
    ajaxBRequestCallFn("../xtDbInfo/listAll",{},function(result){
        $("#"+id).empty();
        result = result.data;
        var str = "<option value=''>请选择</option>";
        $.each(result, function(i, item){
            var xt_dbinfo_id = item.xt_dbinfo_id;
            var xt_dbinfoName = item.xt_dbinfoName;
            str += "<option value=" + xt_dbinfo_id + ">" + xt_dbinfoName + "</option>";
        })
        $("#"+id).append(str);
    });
}

//加载全部表
function getTableList(id){
    var xt_dbinfo_id = $('#xt_dbinfo_id').val();
    if(null == xt_dbinfo_id || '' == xt_dbinfo_id){
        toastrBoot(4,"请选择数据源");
        return;
    }
    ajaxBRequestCallFn("../xtGenerator/table/list?xt_dbinfo_id="+xt_dbinfo_id,{},function(result){
        $("#"+id).empty();
        result = result.data;
        var str = "<option value=''>请选择</option>";
        $.each(result, function(i, item){
            var table_NAME = item.table_NAME;
            var table_COMMENT = item.table_COMMENT;
            if(null == table_COMMENT || "" == table_COMMENT){
                table_COMMENT =  item.table_NAME;
            }
            str += "<option value=" + table_NAME + ">" + table_COMMENT + "</option>";
        })
        $("#"+id).append(str);
    },null,"POST");
}

/**
 * 数据源切换
 * @param thiz
 */
function changeDbInfo(thiz){
    getTableList("xt_generator_tbname");//加载表集合
    getTableColumnPkList("xt_generator_tb_columnname",$('#xt_generator_tbname').val());
    // getColumnList();//列表”列“
    // createSearchHeader();//查询条件"清空并创建Header"
    // getPageConfigColumnList();//新增 编辑 详情等页面
    clearAll();
}

/**
 * 表change联动效果
 * @param thiz
 */
function changeTable(thiz){
    var xt_generator_tbname = thiz.value;
    getTableColumnPkList("xt_generator_tb_columnname",xt_generator_tbname);
    getColumnList();//列表”列“
    createSearchHeader();//查询条件"清空并创建Header"
    getPageConfigColumnList();//新增 编辑 详情等页面
    createOneTwoManyHeader();//一对多
    $("#xt_generator_tbcomment").val($("#xt_generator_tbname").find("option:selected").text());
}

/**
 * 根据表名查找主键字段
 * @param id
 * @param xt_generator_tbname
 */
function getTableColumnPkList(id,xt_generator_tbname){
    var xt_dbinfo_id = $('#xt_dbinfo_id').val();
    if(null == xt_dbinfo_id || '' == xt_dbinfo_id){
        toastrBoot(4,"请选择数据源");
        return;
    }
    $("#"+id).empty();
    ajaxBRequestCallFn("../xtGenerator/table/column/pk/list?xt_generator_tbname="+xt_generator_tbname,{"xt_dbinfo_id":xt_dbinfo_id},function(result){
        result = result.data;
        var str = "<option value=''>请选择</option>";
        for(var i in result){
            var column_NAME = result[i].column_NAME;
            var column_COMMENT = result[i].column_COMMENT;
            if(null == column_COMMENT || '' == column_COMMENT){
                column_COMMENT = result[i].column_NAME
            }
            str += "<option value=" + column_NAME + ">" + column_COMMENT + "</option>";
        }
        $("#"+id).append(str);
    });
}

/**
 * 根据表名查找主键字段
 * @param id
 * @param xt_generator_tbname
 */
function getDisks(id){
    $("#"+id).empty();
    ajaxBRequestCallFn("../xtGenerator/disks",{},function(result){
        result = result.data;
        var str;
        $.each(result, function(i, item){
            var disks = item.disks;
            var disksName = item.disksName;
            str += "<option value='"+disks+"'>"+disksName+"</option>";
        })
        $("#"+id).append(str);
    });
}

///////////////////////////////////////////////////////列表展示字段开始////////////////////////////////////////////

function createGridColumnHeader() {
    validatorDestroy('defaultGridForm');
    $("#grid_col_rows").empty();
    var rowsHtml =
        '<div class="form-group m-form__group row" style="background: #6f47d0;">'+
        '<label class="col-lg-3 col-form-label" style="color: #fff;" jEhcLang="grid_column_NAME">字段</label>'+
        '<label class="col-lg-3 col-form-label" style="color: #fff;" jEhcLang="grid_column_COMMENT">标签显示值</label>'+
        '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="grid_data_TYPE">类型</label>'+
        '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="grid_column_KEY">主键</label>'+
        '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="grid_column_NAME">操作</label>'
    '</div>';
    $("#grid_col_rows").append(rowsHtml);
    reValidator('defaultGridForm');
}
/**
 * 列表字段
 */
function getColumnList(){
    var xt_dbinfo_id = $('#xt_dbinfo_id').val();
    if(null == xt_dbinfo_id || '' == xt_dbinfo_id){
        toastrBoot(4,"请选择数据源");
        return;
    }
    createGridColumnHeader();
    var xt_generator_tbname = $("#xt_generator_tbname").val();
    var rowsHtml;
    ajaxBRequestCallFn("../xtGenerator/table/column/list?xt_generator_tbname="+xt_generator_tbname+"&xt_dbinfo_id="+xt_dbinfo_id,{},function(result){
        result = result.data;
        $.each(result, function(i, item){
            var column_NAME = item.column_NAME;
            var column_COMMENT = item.column_COMMENT;
            if(null == column_COMMENT || "" == column_COMMENT){
                column_COMMENT =  column_NAME;
            }
            validatorDestroy('defaultGridForm');
            var uuid = guid();
            rowsHtml =
                '<div class="form-group m-form__group row" id="gridRows'+uuid+'">'+
                    '<div class="col-lg-3">'+
                        '<input class="form-control" type="text" readonly id="grid_column_NAME'+uuid+'" value="'+column_NAME+'"  name="column_name">'+
                    '</div>'+
                    '<div class="col-lg-3">'+
                        '<input class="form-control" type="text" data-bv-notempty data-bv-notempty-message="请输入" id="grid_column_COMMENT'+uuid+'" value="'+column_COMMENT+'" name="column_comment" placeholder="请输入">'+
                    '</div>'+

                    '<div class="col-lg-2">'+
                        '<input class="form-control" type="text" readonly id="grid_data_TYPE'+uuid+'" value="'+item.data_TYPE+'" name="data_type">'+
                    '</div>'+

                    '<div class="col-lg-2">'+
                        '<input class="form-control" type="text" readonly id="grid_column_KEY'+uuid+'" value="'+item.column_KEY+'" name="column_key">'+
                    '</div>'+

                    '<div class="col-lg-2">'+
                        '<a href=javascript:delGridRows("'+uuid+'")  class="btn btn-default">删除</a>'+
                    '</div>'
                '</div>';
            $("#grid_col_rows").append(rowsHtml);
            reValidator('defaultGridForm');
        })
    }, null,'POST');
}

/**
 * 刷新列表
 */
function refreshColumnList(){
    msgTishCallFnBoot("刷新可能会导致列表字段重置，确认刷新？",function(){
        getColumnList();
    });
}

/**
 * 删除列表字段
 * @param uuid
 */
function delGridRows(rowID){
    msgTishCallFnBoot("确认删除？",function(){
        validatorDestroy('defaultGridForm');
        $("#gridRows"+rowID).remove();
        reValidator('defaultGridForm');
    });
}


$('#myTab a').click(function (e) {
    e.preventDefault()
    $(this).tab('show');
    $.fn.dataTable.tables( {visible: true, api: true} ).columns.adjust();
})
///////////////////////////////////////////////////////列表展示字段结束////////////////////////////////////////////


///////////////////////////////////////////////////////查询条件开始////////////////////////////////////////////
/**
 * 创建查询列Header
 */
function createSearchHeader(){
    validatorDestroy('defaultSearchForm');
    $("#search_col_rows").empty();
    var rowsHtml =
        '<div class="form-group m-form__group row" style="background: #6f47d0;">'+
            '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="xt_generator_search_name">字段</label>'+
            '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="xt_generator_search_label">中文名称</label>'+
            '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="xt_generator_search_label_position">标签位置</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="xt_generator_search_label_length">标签长度</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="xt_generator_search_flag">标识</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="xt_generator_search_type">类型</label>'+
            '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="xt_script_id">脚本</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="xt_generator_search_type">操作</label>'+
        '</div>';
    $("#search_col_rows").append(rowsHtml);
    reValidator('defaultSearchForm');
}

/**
 *
 */
function newSearchRows(){
    var xt_generator_tbname = $("#xt_generator_tbname").val()
    if(undefined === xt_generator_tbname||null == xt_generator_tbname || "" == xt_generator_tbname){
        window.parent.toastrBoot(2, "请到后台配置选项卡中选择您要生成的表");
        return;
    }
    var newSearchModalCount = 0 ;
    $('#searchColModal').modal({backdrop: 'static', keyboard: false});
    $('#searchColModal').on("shown.bs.modal",function(){
        if(++newSearchModalCount == 1){
            getSearchColumnList(xt_generator_tbname);
        }
    });
}

/**
 *
 */
function getSearchColumnList(xt_generator_tbname){
    var xt_dbinfo_id = $('#xt_dbinfo_id').val();
    if(null == xt_dbinfo_id || '' == xt_dbinfo_id){
        toastrBoot(4,"请选择数据源");
        return;
    }
    /////////////jehc扩展属性目的可方便使用（boot.js文件datatablesCallBack方法使用） 如弹窗分页查找根据条件 可能此时的form发生变化 此时 可以解决该类问题
    var opt = {
        searchformId:'searchForm'
    };
    var options = DataTablesList.listOptions({
        ajax:function (data, callback, settings){datatablesListCallBack(data, callback, settings,"../xtGenerator/table/column/list?xt_generator_tbname="+xt_generator_tbname+"&xt_dbinfo_id="+xt_dbinfo_id,opt);},//渲染数据
        //在第一位置追加序列号
        fnRowCallback:function(nRow, aData, iDisplayIndex){
            jQuery('td:eq(0)', nRow).html(iDisplayIndex+1);
            return nRow;
        },
        order:[],//取消默认排序查询,否则复选框一列会出现小箭头
        //列表表头字段
        colums:[
            {
                data:"column_NAME",
                width:"50px"
            },
            {
                data:"column_NAME",
                width:"150px",
                render:function(data, type, row, meta) {
                    var column_NAME = row.column_NAME;
                    var column_COMMENT = row.column_COMMENT;
                    return '<a href=javascript:doSelectSearchCol("'+column_NAME+'","'+column_COMMENT+'")  class="btn btn-default">确定</a>';
                }
            },
            {
                data:'column_NAME'
            },
            {
                data:'column_COMMENT'
            },
            {
                data:'data_TYPE'
            },
            {
                data:'character_MAXIMUM_LENGTH'
            },
            {
                data:'is_NULLABLE'
            }
        ]
    });
    columnGrid=$('#searchDatatables').dataTable(options);
}

/**
 * 动态创建查询框
 */
function createSearchField(uuid){
    var rowsHtml =
        '<div class="form-group m-form__group row" id="rows'+uuid+'">'+
            '<div class="col-lg-2">'+
                '<input class="form-control" type="text" readonly id="xt_generator_search_name'+uuid+'"  name="searchFieldList[][xt_generator_search_name]">'+
            '</div>'+
            '<div class="col-lg-2">'+
                '<input class="form-control" type="text" maxlength="20" id="xt_generator_search_label'+uuid+'" data-bv-notempty data-bv-notempty-message="请输入中文名称" name="searchFieldList[][xt_generator_search_label]" placeholder="请输入中文名称">'+
            '</div>'+
            '<div class="col-lg-2">'+
                '<select class="form-control" id="xt_generator_search_label_position'+uuid+'"  name="searchFieldList[][xt_generator_search_label_position]" placeholder="请选择">'+
                    '<option value="">请选择</option>'+
                    '<option value="居左">居左</option>'+
                    '<option value="居上">居上</option>'+
                '</select>'+
            '</div>'+
            '<div class="col-lg-1">'+
                '<input class="form-control" type="text" id="xt_generator_search_label_length'+uuid+'" data-bv-numeric data-bv-numeric-message="此项为数字类型" name="searchFieldList[][xt_generator_search_label_length]" placeholder="请输入Label长度">'+
            '</div>'+
            '<div class="col-lg-1">'+
                '<select class="form-control" id="xt_generator_search_flag'+uuid+'" name="searchFieldList[][xt_generator_search_flag]" placeholder="请选择" onchange=changeSearchFlag("'+uuid+'")>'+
                    '<option value="">请选择</option>'+
                    '<option value="包含">包含</option>'+
                    '<option value="等于">等于</option>'+
                    '<option value="大于等于">大于等于</option>'+
                    '<option value="小于等于">小于等于</option>'+
                    '<option value="大于">大于</option>'+
                    '<option value="小于">小于</option>'+
                    '<option value="范围">范围</option>'+
                '</select>'+
            '</div>'+
            '<div class="col-lg-1">'+
                '<select class="form-control" id="xt_generator_search_type'+uuid+'" name="searchFieldList[][xt_generator_search_type]" onchange=changeSearchType("'+uuid+'") placeholder="请选择">'+
                    '<option value="">请选择</option>'+
                    '<option value="文本框">文本框</option>'+
                    '<option value="文本域">文本域</option>'+
                    '<option value="下拉框">下拉框</option>'+
                    '<option value="文件框">文件框</option>'+
                '</select>'+
            '</div>'+
            '<div class="col-lg-2">'+
                '<select class="form-control" id="xt_script_id'+uuid+'" name="searchFieldList[][xt_script_id]" placeholder="请选择">'+
                    '<option value="">请选择</option>'+
                '</select>'+
            '</div>'+
            '<div class="col-lg-1">'+
                '<a href=javascript:delSearchRows("'+uuid+'")  class="btn btn-default">删除</a>'+
            '</div>'
        '</div>';
    return rowsHtml;
}

/**
 * 删除行
 * @param uuid
 */
function delSearchRows(rowID) {
    msgTishCallFnBoot("确认删除？",function(){
        validatorDestroy('defaultSearchForm');
        $("#rows"+rowID).remove();
        reValidator('defaultSearchForm');
    });
}

/**
 *
 * @param id
 * @param thiz
 */
function changeSearchFlag(id){
    var xt_generator_search_type = $("#xt_generator_search_type"+id).val();
    if('下拉框'== xt_generator_search_type){
        window.parent.toastrBoot(2, "类型为下拉框，查询条件只能为<font color='red'>等于</font>");
        $("#xt_generator_search_flag"+id).val('等于');
    }
}

/**
 *
 * @param id
 */
function changeSearchType(id){
    var xt_generator_search_type = $("#xt_generator_search_type"+id).val();
    if('下拉框'== xt_generator_search_type){
        window.parent.toastrBoot(2, "类型为下拉框，查询条件只能为<font color='red'>等于</font>");
        $("#xt_generator_search_flag"+id).val('等于');
    }

    if(null != xt_generator_search_type && '' != xt_generator_search_type){
        if('下拉框'!= xt_generator_search_type){
            $("#xt_generator_search_type"+id).val("");
            $("#xt_script_id"+id).val("");
        }else{
            $("#xt_generator_search_flag"+id).val('等于');
        }
    }
}

/**
 *
 */
function doSelectSearchCol(column_NAME,column_COMMENT) {
    var array = document.getElementsByName("xt_generator_search_name");
    for(var i in array){
        if(array[i].value == column_NAME){
            window.parent.toastrBoot(2, "您选择的该字段已经设置过了，不能再次设置！");
            return;
        }
    }
    msgTishCallFnBoot("确认选择字段名："+column_NAME+",<br>标签为："+column_COMMENT+"?",function(){
        validatorDestroy('defaultSearchForm');
        var uuid = guid();
        $("#search_col_rows").append(createSearchField(uuid));
        $('#xt_generator_search_name'+uuid).val(column_NAME);
        $('#xt_generator_search_label'+uuid).val(column_COMMENT);
        $('#xt_generator_search_label_position'+uuid).val("居上");
        $('#xt_generator_search_flag'+uuid).val("包含");
        $('#xt_generator_search_label_length'+uuid).val("70");
        $('#xt_generator_search_type'+uuid).val("文本框");
        reValidator('defaultSearchForm');
        $('#searchColModal').modal('hide');
    });
}
///////////////////////////////////////////////////////查询条件结束////////////////////////////////////////////

///////////////////////////////////////////////////////新增 编辑 详情页面开始////////////////////////////////////////////
/**
 * 刷新增 编辑 详情 等页面字段
 */
function refreshPageConfigList(){
    msgTishCallFnBoot("刷新可能会导致新增-编辑-详情配置中字段重置，确认刷新？",function(){
        getPageConfigColumnList();
    });
}

/**
 *
 */
function createPageConfigColumnHeader() {
    validatorDestroy('defaultPageConfigForm');
    $("#page_col_rows").empty();
    var rowsHtml =
        '<div class="form-group m-form__group row" style="background: #6f47d0;">'+
            '<label class="col-lg-2 col-form-label" style="color: #fff;" jEhcLang="COLUMN_NAME">字段</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="COLUMN_COMMENT">标签</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="DATA_TYPE">字段类型</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="CHARACTER_MAXIMUM_LENGTH">长度</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="IS_NULLABLE">必填</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="COLUMN_KEY">主键</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="column_label_position">位置</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="column_label_anchor">宽度</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="column_type">类型</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="xt_script_id">脚本</label>'+
            '<label class="col-lg-1 col-form-label" style="color: #fff;" jEhcLang="isHidden">隐藏</label>'+
        '</div>';
    $("#page_col_rows").append(rowsHtml);
    reValidator('defaultPageConfigForm');
}

/**
 * 新增明细编辑页面字段
 */
function getPageConfigColumnList(){
    var xt_dbinfo_id = $('#xt_dbinfo_id').val();
    if(null == xt_dbinfo_id || '' == xt_dbinfo_id){
        toastrBoot(4,"请选择数据源");
        return;
    }
    var xt_generator_tbname = $("#xt_generator_tbname").val();
    createPageConfigColumnHeader();
    ajaxBRequestCallFn("../xtGenerator/table/column/list?xt_generator_tbname="+xt_generator_tbname+"&xt_dbinfo_id="+xt_dbinfo_id,{},function(result){
        result = result.data;
        $.each(result, function(i, item){
            var column_NAME = item.column_NAME;
            var column_COMMENT = item.column_COMMENT;
            if(null == column_COMMENT || "" == column_COMMENT){
                column_COMMENT =  column_NAME;
            }
            var column_KEY = item.column_KEY;
            if(column_KEY ==  null){
                column_KEY = "";
            }
            validatorDestroy('defaultPageConfigForm');
            var uuid = guid();
            rowsHtml =
                '<div class="form-group m-form__group row" id="pageRows'+uuid+'">'+
                    '<div class="col-lg-2">'+
                        '<input class="form-control" type="text" readonly id="page_column_NAME'+uuid+'" value="'+column_NAME+'"  name="COLUMN_NAME">'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<input class="form-control" type="text" data-bv-notempty data-bv-notempty-message="请输入" id="page_column_COMMENT'+uuid+'" value="'+column_COMMENT+'"  name="COLUMN_COMMENT">'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<input class="form-control" type="text" readonly id="page_data_TYPE'+uuid+'" value="'+item.data_TYPE+'"  name="DATA_TYPE">'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<input class="form-control" type="text" readonly id="page_character_MAXIMUM_LENGTH'+uuid+'" value="'+item.character_MAXIMUM_LENGTH+'"  name="CHARACTER_MAXIMUM_LENGTH">'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<input class="form-control" type="text" readonly id="page_is_NULLABLE'+uuid+'" value="'+item.is_NULLABLE+'"  name="IS_NULLABLE">'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<input class="form-control" type="text" readonly id="page_column_KEY'+uuid+'" value="'+column_KEY+'" name="COLUMN_KEY">'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<select class="form-control" id="page_column_label_position'+uuid+'" name="column_label_position" placeholder="请选择">'+
                            '<option value="">请选择</option>'+
                            '<option value="居左">居左</option>'+
                            '<option value="居上">居上</option>'+
                        '</select>'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<input class="form-control" type="text" maxlength="3" data-bv-numeric data-bv-numeric-message="此项为数字类型" id="page_column_label_anchor'+uuid+'" value="100"  name="column_label_anchor">'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<select class="form-control" id="page_column_type'+uuid+'" name="column_type" onchange=changePageType("'+uuid+'") placeholder="请选择">'+
                            '<option value="">请选择</option>'+
                            '<option value="文本框">文本框</option>'+
                            '<option value="文本域">文本域</option>'+
                            '<option value="下拉框">下拉框</option>'+
                            '<option value="文件框">文件框</option>'+
                        '</select>'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<select class="form-control" id="page_xt_script_id'+uuid+'" name="xt_script_id" placeholder="请选择">'+
                            '<option value="">请选择</option>'+
                        '</select>'+
                    '</div>'+
                    '<div class="col-lg-1">'+
                        '<select class="form-control" id="page_isHidden'+uuid+'" name="isHidden" placeholder="请选择">'+
                            '<option value="否">否</option>'+
                            '<option value="是">是</option>'+
                        '</select>'+
                    '</div>'+
                '</div>';
            $("#page_col_rows").append(rowsHtml);
            reValidator('defaultPageConfigForm');
        });
    }, null,'POST');
}

/**
 *
 * @param id
 */
function changePageType(id){
    var page_column_type = $("#page_column_type"+id).val();
    var DATA_TYPE = $("#page_data_TYPE"+id).val();
    var CHARACTER_MAXIMUM_LENGTH = $("#page_character_MAXIMUM_LENGTH"+id).val();
    if(DATA_TYPE == 'VARCHAR' || DATA_TYPE == 'CHAR' || DATA_TYPE == 'TEXT' || DATA_TYPE == 'LONGTEXT' || DATA_TYPE == 'LONGBLOB'){
        if('文件框'== page_column_type && CHARACTER_MAXIMUM_LENGTH <32){
            $("#page_column_type"+id).val('');
            window.parent.toastrBoot(2, "你所选的文件框字段长度小于32位，必须大于等于32位才可选择");
            return;
        }
    }else{
        $("#page_column_type"+id).val('');
        window.parent.toastrBoot(2, "字段类型为VARCHAR，CHAR时，才可选择该项");
        return;
    }
}
///////////////////////////////////////////////////////新增 编辑 详情页面结束////////////////////////////////////////////


//验证并获取配置查询字段JSON规则
function getXtGeneratorSearchFileJSON(){
    var bootform = $('#defaultSearchForm');
    var boostrapValidator =bootform.data('bootstrapValidator');
    boostrapValidator.validate();
    if(!boostrapValidator.isValid()){
        window.parent.toastrBoot(4,"存在不合法的字段!");
        return false;
    }
    var searchValue = JSON.stringify($("#defaultSearchForm").serializeJSON());
    return searchValue;
}




//验证并获取配置GridList字段JSON规则
function getXtGeneratorGridListJSON(){
    var bootform = $('#defaultGridForm');
    var boostrapValidator =bootform.data('bootstrapValidator');
    boostrapValidator.validate();
    if(!boostrapValidator.isValid()){
        window.parent.toastrBoot(4,"存在不合法的字段!");
        return false;
    }
    return formToJson("defaultGridForm");
}


//验证并获取配置新增，编辑，明细等表单字段JSON规则
function getXtGeneratorFormListJSON(){
    var bootform = $('#defaultPageConfigForm');
    var boostrapValidator =bootform.data('bootstrapValidator');
    boostrapValidator.validate();
    if(!boostrapValidator.isValid()){
        window.parent.toastrBoot(4,"存在不合法的字段!");
        return false;
    }
    $.fn.serializeObject = function(){
        var o = {};
        var a = this.serializeArray();
        $.each(a, function() {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };
    return formToJson("defaultPageConfigForm");
}